#include "client.h"
#include "session.h"
#include "gui/clientproxy.h"
#include "rectification/video.h"


//接收自server的数据，处理接口
void Client::doWork(const Protocal& data)
{
	// Session::doWork(p);
	char type = data.head.id;
	std::vector<char> body = data.body;
	switch ((Catag)type) {
		case Catag::PLAIN:
			{

			}
		case Catag::VIDEO:
			{
				Video v(body, data.head.counter);
				Response r = v.GetHandleResult();
				//将json处理后的数据，显示到指定对象中.
				if (r.name != "") {
					ClientProxy::getInstance().fillResponseQueue(r);
				}
				v.PostPlay();
				break;
			}
		default:
			ALOGD("Protocal Id error: %c\n", type);
	}
}


Client::Client(int id)
	:Session(id),dp(this)
{
	dp.Create_Socket();
	auto on_connect = [this](){
		setStatus(SESSION::CONNECTED);
	};
	dp.Connect("192.168.0.107", 6666, on_connect);
	start(dp.GetTcpHandle());
}

Client::~Client()
{
	dp.Stop();
}
